package com.movieproject.src;

import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.movieproject.daos.ReviewDAO;
import com.movieproject.dataobjects.Movie;
import com.movieproject.dataobjects.Queue;
import com.movieproject.dataobjects.Review;

@Controller
@RequestMapping(value = "/addcomment")
public class AddComment {

	@RequestMapping(method = RequestMethod.GET)

	public String addComment(Map<String, Object> model) {
		
		Review commentForm = new Review();
		model.put("commentForm", commentForm);

		//name of jsp file
		return "comment";
	}
	@RequestMapping(method = RequestMethod.POST)
	public String processReview(@ModelAttribute("commentForm") Review review,
			Map<String, Object> model) {

		ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");

		ReviewDAO reviewDAO = (ReviewDAO) context.getBean("reviewDAO");
		
		int a = review.getUserID();
		int b = review.getMovieID();
		String c = review.getReview();
		int d = review.getScore();


		Review q = new Review(a,b,c,d);
		reviewDAO.insert(q);
		
		
		
		return "commentadded";
	}
	
}
